﻿using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Medicalsystem.MCP.FormDesigner.Property;

namespace Medicalsystem.MCP.FormDesigner.MyControls
{
    /// <summary>
    /// PanelCtl 控件与属性编辑器的交互
    /// </summary>
    public class GetPanelCtlProperty : GetCtrlContainerProperty
    {
        public GetPanelCtlProperty(PanelCtl panelCtl)
            : base(panelCtl)
        {
            _panelCtl = panelCtl;
        }

        private PanelCtl _panelCtl = null;

        /// <summary>
        /// 自动滚动
        /// </summary>
        [CategoryAttribute("布局")]
        [ShowChinese("自动滚动")]
        [Description("指示当控件内容大于它的可见区域时是否自动显示滚动条")]
        [Browsable(true)]
        public bool AutoScroll
        {
            get
            {
                return _panelCtl.AutoScroll;
            }
            set
            {
                this._panelCtl.AutoScroll = value;
            }
        }

        /// <summary>
        /// 背景图像
        /// </summary>
        [CategoryAttribute("外观")]
        [ShowChinese("背景图像")]
        [Description("用于该窗体的背景图像")]
        public Image BackgroundImage
        {
            get
            {
                return _panelCtl.BackgroundImage;
            }
            set
            {
                if (value != null)
                {
                    System.IO.MemoryStream ImageMem = new System.IO.MemoryStream();
                    value.Save(ImageMem, value.RawFormat);

                    if (ImageMem.Length > 524288)
                    {
                        MessageBox.Show("请选择小于512KB的图片资源", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        _panelCtl.BackgroundImage = value;
                    }
                }
                else
                {
                    _panelCtl.BackgroundImage = value;
                }
            }
        }

        /// <summary>
        /// 图像布局
        /// </summary>
        [CategoryAttribute("外观")]
        [ShowChinese("图像布局")]
        [Description("用于组件的背景图像布局")]
        public ImageLayout BackgroundImageLayout
        {
            get
            {
                return _panelCtl.BackgroundImageLayout;
            }
            set
            {
                _panelCtl.BackgroundImageLayout = value;
            }
        }

        /// <summary>
        /// 设置属性值
        /// </summary>
        /// <param name="propertyName"></param>
        /// <param name="value"></param>
        public override void SetProperty(string propertyName, object value)
        {
            switch (propertyName.ToLower())
            {
                case "borderstyle":
                    this._panelCtl.BorderStyle = (System.Windows.Forms.BorderStyle)value;
                    break;

                default:
                    base.SetProperty(propertyName, value);
                    break;
            }
        }
    }
}